package 课上练习0422_scala

/**
 * 排序Ordering+隐式参数
 */
object Scala_04_order {
  // 按照age升序，weight降序
  def main(args: Array[String]): Unit = {
    case class Student(name: String, age: Int, weight: Int)
    val student = List(Student("jason", 20, 50), Student("ammy", 21, 45), Student("leo", 21, 40))
    implicit val defaultOrdering: Ordering[Student] = (x, y) =>
      if (x.age == y.age) y.weight - x.weight else x.age - y.age
    student.sorted.foreach(println)
  }
}
